package com.cenwangkeji.resident.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.cenwangkeji.resident.R;
import com.cenwangkeji.resident.model.Constant;
import com.cenwangkeji.resident.model.bean.BannerBean;
import com.cenwangkeji.resident.model.bean.FileIconBean;
import com.cenwangkeji.resident.presenter.fragment.FilePresenter;
import com.cenwangkeji.resident.ui.activity.AssessActivity;
import com.cenwangkeji.resident.ui.activity.BasicInfoActivity;
import com.cenwangkeji.resident.ui.activity.FamilyActivity;
import com.cenwangkeji.resident.ui.activity.MedicalActivity;
import com.cenwangkeji.resident.ui.activity.ServicePackageAllActivity;
import com.cenwangkeji.resident.ui.activity.ServicePackageEvaluateActivity;
import com.cenwangkeji.resident.ui.activity.SignActivity;
import com.cenwangkeji.resident.ui.activity.SpecialListActivity;
import com.cenwangkeji.resident.ui.activity.TestingActivity;
import com.cenwangkeji.resident.ui.adapter.FileAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lws.basic.base.BaseFragment;
import com.lws.basic.utils.common.MyToast;
import com.youth.banner.Banner;
import com.youth.banner.Transformer;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @松 on 2019/10/22 16:40
 * 档案
 */
public class FileFragment extends BaseFragment implements FilePresenter.I,BaseQuickAdapter.OnItemClickListener {
    @BindView(R.id.rv)
    RecyclerView mRv;
    @BindView(R.id.banner)
    Banner mBanner;
    Unbinder unbinder;
    private List<FileIconBean> mList;
    private FilePresenter mPresenter = new FilePresenter(this);

    @Override
    public int setLayoutId() {
        return R.layout.fragment_file;
    }



    @Override
    protected void initView(View rootView) {
        super.initView(rootView);
        unbinder = ButterKnife.bind(this, rootView);
    }

    @Override
    protected void initData() {
        super.initData();
        showLoading();
        initRecyelerView();
        mPresenter.getBanner();

    }

    private void initRecyelerView(){
        mList = new ArrayList<>();
        mList.add(new FileIconBean(R.mipmap.ic_files1, "基本档案"));
        mList.add(new FileIconBean(R.mipmap.ic_files2, "自测档案"));
       // mList.add(new FileIconBean(R.mipmap.ic_files3, "体检信息"));
        mList.add(new FileIconBean(R.mipmap.ic_files4, "专项档案"));
        mList.add(new FileIconBean(R.mipmap.ic_files5, "评估报告"));
        mList.add(new FileIconBean(R.mipmap.ic_files6, "家庭成员"));
        mRv.setLayoutManager(new GridLayoutManager(getContext(), 2));
        FileAdapter adapter = new FileAdapter(mList);
        adapter.setOnItemClickListener(this);
        mRv.setAdapter(adapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
       switch (mList.get(position).getIcon()){
           case R.mipmap.ic_files1://基本档单
               startActivity(new Intent(getActivity(), BasicInfoActivity.class));
               break;
           case R.mipmap.ic_files2://自测
               startActivity(new Intent(getActivity(), TestingActivity.class));
               break;
           case R.mipmap.ic_files3://体检
               startActivity(new Intent(getActivity(), MedicalActivity.class));
               break;
           case R.mipmap.ic_files4://专项
               startActivity(new Intent(getActivity(), SpecialListActivity.class));
               break;
           case R.mipmap.ic_files5://评估报告
               startActivity(new Intent(getActivity(), AssessActivity.class));
               break;
           case R.mipmap.ic_files6:
               startActivity(new Intent(getActivity(), FamilyActivity.class));
               break;

       }
    }


    @OnClick({R.id.iv_signing, R.id.iv_assess, R.id.tv_signing, R.id.tv_assess, R.id.tv_service, R.id.tv_estimate, R.id.iv_service, R.id.iv_estimate})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_signing://签约
            case R.id.tv_signing:
                startActivity(new Intent(getActivity(), SignActivity.class));
                break;
            case R.id.iv_assess:
            case R.id.tv_assess:
                startActivity(new Intent(getActivity(), ServicePackageEvaluateActivity.class));
                break;
            case R.id.tv_service:
            case R.id.iv_service:
                Intent intent = new Intent(getActivity(), ServicePackageAllActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_estimate:
            case R.id.iv_estimate://评估报告
                startActivity(new Intent(getActivity(), AssessActivity.class));
                break;
        }
    }

    @Override
    public void onBanner(BannerBean bannerbean) {
        if (bannerbean.getData().size() >0) {
            ArrayList<String> list = new ArrayList<>();
            //   设置图片集合
            for (int i = 0; i < bannerbean.getData().size(); i++) {
                list.add(Constant.base + bannerbean.getData().get(i));
            }
            mBanner.setImageLoader(new ImageLoader() {
                @Override
                public void displayImage(Context context, Object path, ImageView imageView) {
                    Glide.with(context).load(path).into(imageView);
                }

            }).setImages(list).setBannerAnimation(Transformer.CubeIn).setDelayTime(3000).start();

        } else {
            MyToast.show("轮播图为空");
        }
        dismissLoading();
    }
}
